/**
 * 查找树的最大深度
 */
class Solution {

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        TreeNode node21 = new TreeNode(2);
        TreeNode node22 = new TreeNode(2);
        TreeNode node31 = new TreeNode(3);
        TreeNode node32 = new TreeNode(3);
        TreeNode node42 = new TreeNode(4);
        root.left = node21;
        root.right = node22;
        node21.right = node31;
        node22.left = node32;
        node22.right = node42;
        System.out.println(maxDepth(root));
    }

    public static int maxDepth(TreeNode root) {
        if (null == root) {
            return 0;
        }
        return Math.max(maxDepth(root.left, 1), maxDepth(root.right, 1));
    }

    public static int maxDepth(TreeNode node, int len) {
        if (null == node) {
            return len;
        }
        return Math.max(maxDepth(node.left, len + 1), maxDepth(node.right, len + 1));
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}